package com.code.frame.basecode.jdk8;

import java.time.*;

public class JavaDate1 {
    public static void main(String[] args) {
        JavaDate1 java8tester = new JavaDate1();
//        java8tester.testLocalDateTime1();
        java8tester.testZonedDateTime2();
    }
    public void testLocalDateTime1() {
        // 获取当前的日期时间
        LocalDateTime currentTime = LocalDateTime.now();
        System.out.println("当前时间: " + currentTime);//2021-03-02T17:53:33.160
        LocalDate date1 = currentTime.toLocalDate();
        System.out.println("date1: " + date1);// 2021-03-02
        Month month = currentTime.getMonth();
        int day = currentTime.getDayOfMonth();
        int seconds = currentTime.getSecond();
        System.out.println("月: " + month + ", 日: " + day + ", 秒: " + seconds);//月: MARCH, 日: 2, 秒: 33
        LocalDateTime date2 = currentTime.withDayOfMonth(10).withYear(2012);
        System.out.println("date2: " + date2);//2012-03-10T17:53:33.160
        // 12 december 2014
        LocalDate date3 = LocalDate.of(2014, Month.DECEMBER, 12);
        System.out.println("date3: " + date3);//2014-12-12
        // 22 小时 15 分钟
        LocalTime date4 = LocalTime.of(22, 15);
        System.out.println("date4: " + date4);//22:15
        // 解析字符串
        LocalTime date5 = LocalTime.parse("20:15:30");
        System.out.println("date5: " + date5);//20:15:30
    }

    public void testZonedDateTime2() {
        // 获取当前时间日期
        ZonedDateTime date1 = ZonedDateTime.parse("2015-12-03T10:15:30+05:30[Asia/Shanghai]");
        System.out.println("date1: " + date1);// 2015-12-03T10:15:30+08:00[Asia/Shanghai]
        ZoneId id = ZoneId.of("Europe/Paris");
        System.out.println("ZoneId: " + id);//Europe/Paris
        ZoneId currentZone = ZoneId.systemDefault();
        System.out.println("当期时区: " + currentZone);//Asia/Shanghai
    }
}
